<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="Hexo, NexT" />





  <link rel="alternate" href="/atom.xml" title="Likianta Blog" type="application/atom+xml" />






<meta name="description" content="对前四章的学习进行一次回顾和总结，本章集中解决之前的代码中产生的各种bug，尝试翻新结构以及使用更好的开源插件。">
<meta property="og:type" content="article">
<meta property="og:title" content="05 Anykey阶段性总结、bug汇总及解决">
<meta property="og:url" content="https://likianta.coding.me/2017/1201202913/index.html">
<meta property="og:site_name" content="Likianta Blog">
<meta property="og:description" content="对前四章的学习进行一次回顾和总结，本章集中解决之前的代码中产生的各种bug，尝试翻新结构以及使用更好的开源插件。">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://ozurciydg.bkt.clouddn.com/17-11-29/76784126.jpg">
<meta property="og:image" content="http://ozurciydg.bkt.clouddn.com/17-11-23/5028616.jpg">
<meta property="og:image" content="http://ozurciydg.bkt.clouddn.com/17-12-1/89019773.jpg">
<meta property="og:image" content="http://ozurciydg.bkt.clouddn.com/17-11-30/37284633.jpg">
<meta property="og:updated_time" content="2017-12-31T15:26:18.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="05 Anykey阶段性总结、bug汇总及解决">
<meta name="twitter:description" content="对前四章的学习进行一次回顾和总结，本章集中解决之前的代码中产生的各种bug，尝试翻新结构以及使用更好的开源插件。">
<meta name="twitter:image" content="http://ozurciydg.bkt.clouddn.com/17-11-29/76784126.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://likianta.coding.me/2017/1201202913/"/>





  <title>05 Anykey阶段性总结、bug汇总及解决 | Likianta Blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Likianta Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tutorials">
          <a href="/tags/tutorial-catalog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            教程
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://likianta.coding.me/2017/1201202913/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Likianta">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="http://ozurciydg.bkt.clouddn.com/18-2-12/72826549.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Likianta Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">05 Anykey阶段性总结、bug汇总及解决</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-12-01T20:29:13+08:00">
                2017-12-01
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/passport-pandora/" itemprop="url" rel="index">
                    <span itemprop="name">从零开发Anykey</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  3,204
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  14
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>对前四章的学习进行一次回顾和总结，本章集中解决之前的代码中产生的各种bug，尝试翻新结构以及使用更好的开源插件。  </p>
<a id="more"></a>
<h1 id="1-先讲一下如何在真机上调试app"><a href="#1-先讲一下如何在真机上调试app" class="headerlink" title="1. 先讲一下如何在真机上调试app"></a>1. 先讲一下如何在真机上调试app</h1><p>这里以红米Note2手机（MIUI9 开发版）为例：  </p>
<ol>
<li>准备一条可以传输数据的数据线  </li>
<li>手机在开发者选项中启用“USB调试”和“允许USB安装”  </li>
<li>手机连接PC  </li>
<li>在Android Studio中运行AVD，选择“Xiaomi Redmi Note 2”，app将会安装到手机中  </li>
<li>在初次安装中需要自己在手机上点击接受。安装完成后的调试会自动启动app</li>
</ol>
<p>注意事项：  </p>
<ol>
<li>一定要选择<strong>可以传输数据</strong>的数据线  </li>
<li>不同的手机开启开发者选项的方式不同，小米手机（MIUI9 开发版）的开启方式为连续点击MIUI版本号6次进入开发者模式  </li>
<li>如果Android Studio在运行时提示“error：前言中不允许有内容”，则点击<code>菜单栏 - Build - Rebuild Project</code>即可解决  </li>
</ol>
<p>参考：<a href="http://m.blog.csdn.net/wenxin2011/article/details/50845563" target="_blank" rel="noopener">http://m.blog.csdn.net/wenxin2011/article/details/50845563</a>  </p>
<hr>
<h1 id="2-实机测试问题汇总"><a href="#2-实机测试问题汇总" class="headerlink" title="2. 实机测试问题汇总"></a>2. 实机测试问题汇总</h1><h2 id="2-1-首次创建密码后无法进入主界面"><a href="#2-1-首次创建密码后无法进入主界面" class="headerlink" title="2.1. 首次创建密码后无法进入主界面"></a>2.1. 首次创建密码后无法进入主界面</h2><p>这是因为第一章中忘了在LoginActivity中写intent的跳转代码了。  </p>
<p>解决方法：在LoginActivity的“进入（loginOn）”按钮的监听事件中，创建密码成功则<strong>跳转至主界面</strong>。  </p>
<p>修改代码如下：  </p>
<p><code>LoginActivity.java</code>:  </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">LoginActivity</span> <span class="keyword">extends</span> <span class="title">AppCompatActivity</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(Bundle savedInstanceState)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//触发点击事件，监听登录按钮</span></span><br><span class="line">        loginOn.setOnClickListener(<span class="keyword">new</span> View.OnClickListener() &#123;</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onClick</span><span class="params">(View view)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">                <span class="keyword">if</span> (saved_userPassword.equals(<span class="string">"N/A"</span>)) &#123;</span><br><span class="line">                    <span class="comment">//首次使用的业务逻辑</span></span><br><span class="line">           </span><br><span class="line">                    ...</span><br><span class="line"></span><br><span class="line">                    Toast.makeText(LoginActivity.<span class="keyword">this</span>, <span class="string">"创建成功"</span>, Toast.LENGTH_SHORT).show();</span><br><span class="line">                    <span class="comment">//跳转至主界面</span></span><br><span class="line">                    Intent intent = <span class="keyword">new</span> Intent(LoginActivity.<span class="keyword">this</span>, MainActivity.class);</span><br><span class="line">                    LoginActivity.<span class="keyword">this</span>.startActivity(intent);</span><br><span class="line">                    finish();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="2-2-登录界面在输入错误时软键盘不能自动弹出"><a href="#2-2-登录界面在输入错误时软键盘不能自动弹出" class="headerlink" title="2.2. 登录界面在输入错误时软键盘不能自动弹出"></a>2.2. 登录界面在输入错误时软键盘不能自动弹出</h2><ol>
<li>首先修改Enter键的监听，<strong>将返回值改为“true”</strong>。其他代码保持不变  </li>
<li>然后在“进入”按钮的点击监听事件中，判断登录成功，<strong>则强制关闭软键盘</strong>。其他代码保持不变  </li>
</ol>
<p>修改代码如下：  </p>
<p><code>LoginActivity.java</code>:  </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">LoginActivity</span> <span class="keyword">extends</span> <span class="title">AppCompatActivity</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(Bundle savedInstanceState)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//触发点击事件，监听登录按钮</span></span><br><span class="line">        loginOn.setOnClickListener(<span class="keyword">new</span> View.OnClickListener() &#123;</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onClick</span><span class="params">(View view)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">                <span class="keyword">if</span> (saved_userPassword.equals(<span class="string">"N/A"</span>)) &#123;</span><br><span class="line">                    <span class="comment">//首次使用的业务逻辑</span></span><br><span class="line">                    ...</span><br><span class="line"></span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="comment">//判断输入的密码是否正确</span></span><br><span class="line">                    <span class="keyword">if</span> (passwordValue.equals(saved_userPassword)) &#123;</span><br><span class="line"></span><br><span class="line">                        <span class="comment">//通过调用输入管理器来隐藏软键盘</span></span><br><span class="line">                        InputMethodManager inputMethodManager = (InputMethodManager) etPassword.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);</span><br><span class="line">                        inputMethodManager.hideSoftInputFromWindow(etPassword.getWindowToken(), <span class="number">0</span>); <span class="comment">//强制隐藏软键盘</span></span><br><span class="line"></span><br><span class="line">                        ...</span><br><span class="line"></span><br><span class="line">                    &#125;</span><br><span class="line">                    </span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">        </span><br><span class="line">        <span class="comment">//另外再设置一个监听软键盘输入，当输入Enter的时候，也能触发上面的登录按钮</span></span><br><span class="line">        etPassword.setOnKeyListener(<span class="keyword">new</span> View.OnKeyListener() &#123;</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onKey</span><span class="params">(View view, <span class="keyword">int</span> i, KeyEvent keyEvent)</span> </span>&#123;</span><br><span class="line">                <span class="keyword">if</span> (i == keyEvent.KEYCODE_ENTER) &#123;</span><br><span class="line">                    loginOn.callOnClick(); <span class="comment">//callOnClick是performClick的简化版，适合简单触发点击监听事件</span></span><br><span class="line">                    <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>参考：Android 手动显示和隐藏软键盘 - 一点点征服 - 博客园 <a href="https://www.cnblogs.com/ldq2016/p/6861128.html" target="_blank" rel="noopener">https://www.cnblogs.com/ldq2016/p/6861128.html</a>  </p>
<h2 id="2-3-密码错误时的提示语不醒目"><a href="#2-3-密码错误时的提示语不醒目" class="headerlink" title="2.3. 密码错误时的提示语不醒目"></a>2.3. 密码错误时的提示语不醒目</h2><p>之前的效果是当密码多次输入错误时，欢迎语文字都不会变化，所以看起来不醒目；<br>下图是更改后的样式——每次密码错误，提示语都会变成红色并且闪烁一下：</p>
<p><img src="http://ozurciydg.bkt.clouddn.com/17-11-29/76784126.jpg" alt="" title="After"></p>
<p>实现思路为：当输入错误时，设置文本颜色为亮红色，然后利用透明度动画AlphaAnimation来完成颜色的由亮到浅的变化（动画持续时间在300-800ms之间）。代码如下所示：</p>
<p><code>LoginActivity.java</code>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">LoginActivity</span> <span class="keyword">extends</span> <span class="title">AppCompatActivity</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(Bundle savedInstanceState)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//判断是否为首次使用</span></span><br><span class="line">        changeLoginWelcome(saved_userPassword); <span class="comment">//将原先的“LoginWelcome”更改为“changeLoginWelcome”，用于专门处理欢迎语的变化</span></span><br><span class="line"></span><br><span class="line">        <span class="comment">//触发点击事件，监听登录按钮</span></span><br><span class="line">        loginOn.setOnClickListener(<span class="keyword">new</span> View.OnClickListener() &#123;</span><br><span class="line">            <span class="meta">@Override</span></span><br><span class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onClick</span><span class="params">(View view)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">                <span class="keyword">if</span> (saved_userPassword.equals(<span class="string">"N/A"</span>)) &#123;</span><br><span class="line">                    <span class="comment">//首次使用的业务逻辑</span></span><br><span class="line">                    ...</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    <span class="comment">//非首次登录时的常规业务</span></span><br><span class="line">                    <span class="keyword">if</span> (passwordValue.equals(saved_userPassword)) &#123;</span><br><span class="line">                        ...</span><br><span class="line">                    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                        <span class="comment">//密码错误时的业务</span></span><br><span class="line">                        changeLoginWelcome(<span class="string">"WRONG_CODE"</span>); <span class="comment">//欢迎语的变化放在changeLoginWelcome中处理</span></span><br><span class="line"></span><br><span class="line">                        etPassword.setText(<span class="string">""</span>); <span class="comment">//重置密码框为空</span></span><br><span class="line">                        </span><br><span class="line">                        <span class="comment">//让输入框重新获取焦点</span></span><br><span class="line">                        etPassword.setFocusable(<span class="keyword">true</span>);</span><br><span class="line">                        etPassword.setFocusableInTouchMode(<span class="keyword">true</span>);</span><br><span class="line">                        etPassword.requestFocus();</span><br><span class="line">                        <span class="comment">//通过调用输入管理器来自动弹出软键盘</span></span><br><span class="line">                        InputMethodManager inputMethodManager = (InputMethodManager) etPassword.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);</span><br><span class="line">                        inputMethodManager.showSoftInput(etPassword, <span class="number">0</span>);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">//判断是否为首次使用，不是的话什么都不做</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">changeLoginWelcome</span><span class="params">(String userCode)</span> </span>&#123;</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">switch</span> (userCode) &#123;</span><br><span class="line">            <span class="keyword">case</span> <span class="string">"N/A"</span>:</span><br><span class="line">                <span class="comment">//首次使用时是欢迎语</span></span><br><span class="line">                loginWelcome.setText(<span class="string">"首次使用\n请创建你的主密码"</span>);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">            <span class="keyword">case</span> <span class="string">"WRONG_CODE"</span>:</span><br><span class="line">                <span class="comment">//密码输入错误时的欢迎语</span></span><br><span class="line">                loginWelcome.setText(<span class="string">"密码错误\n请重新登录"</span>);<span class="comment">//在“欢迎词”中显示出错提示</span></span><br><span class="line">                loginWelcome.setTextColor(<span class="number">0xFFF4297E</span>);<span class="comment">//显示为红色</span></span><br><span class="line">                <span class="keyword">final</span> AlphaAnimation alphaAnimation = <span class="keyword">new</span> AlphaAnimation(<span class="number">1.0f</span>, <span class="number">0.6f</span>);<span class="comment">//不透明度的参数取值是小数，范围在0-1之间，0表示完全透明，1表示完全显示</span></span><br><span class="line">                alphaAnimation.setDuration(<span class="number">500</span>);</span><br><span class="line">                alphaAnimation.setFillAfter(<span class="keyword">true</span>); <span class="comment">//表示停留在最终状态上</span></span><br><span class="line">                loginWelcome.setAnimation(alphaAnimation);</span><br><span class="line">                alphaAnimation.startNow();</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="2-4-在登录界面按返回键无法退出"><a href="#2-4-在登录界面按返回键无法退出" class="headerlink" title="2.4. 在登录界面按返回键无法退出"></a>2.4. 在登录界面按返回键无法退出</h2><p>解决方法：新增一个按键监听设置，当按返回键时，则finish掉当前Activity：  </p>
<p><code>LoginActivity.java</code>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">LoginActivity</span> <span class="keyword">extends</span> <span class="title">AppCompatActivity</span> </span>&#123;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(Bundle savedInstanceState)</span> </span>&#123;</span><br><span class="line">        ...</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">//监听按下的按键，如果按下了返回键，则退出登录界面</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">onKeyDown</span><span class="params">(<span class="keyword">int</span> keyCode, KeyEvent keyEvent)</span> </span>&#123;</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">if</span> (keyCode == KeyEvent.KEYCODE_BACK) &#123;</span><br><span class="line">            LoginActivity.<span class="keyword">this</span>.finish();</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">super</span>.onKeyDown(keyCode, keyEvent);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>PS：<strong>为什么要使用<code>finish()</code>，而不使用<code>onDestroy()</code>或者<code>System.exit(0)</code>？</strong>  </p>
<p>finish是把当前Activity关闭，而onDestroy会销毁当前Activity的实例，System.exit(0)则会将当前整个进程给终结掉。<br>在实际使用中会发现，后两者在退出时屏幕会闪一下，而使用finish退出，退出动画更加自然一些。</p>
<p>参考：安卓开发-Activity中finish() onDestroy() 和System.exit()的区别 - CSDN博客 <a href="http://blog.csdn.net/imzoer/article/details/9380807" target="_blank" rel="noopener">http://blog.csdn.net/imzoer/article/details/9380807</a>  </p>
<h2 id="2-5-一进入主界面软键盘就自动弹出"><a href="#2-5-一进入主界面软键盘就自动弹出" class="headerlink" title="2.5. 一进入主界面软键盘就自动弹出"></a>2.5. 一进入主界面软键盘就自动弹出</h2><p>这是因为MainActivity的子分页布局里面有EditText控件，这个EditText会率先获取焦点，导致软键盘检测并触发弹出。<br>解决方法也很简单，在MainActivity中设置键盘默认不许自动弹出即可（只需新增一行代码）：</p>
<p><code>MainActivity.java</code>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MainActivity</span> <span class="keyword">extends</span> <span class="title">AppCompatActivity</span> <span class="keyword">implements</span> <span class="title">View</span>.<span class="title">OnClickListener</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(Bundle savedInstanceState)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//开始绑定按钮</span></span><br><span class="line">        ...</span><br><span class="line"></span><br><span class="line">        <span class="comment">//http://blog.csdn.net/Vivian8725118/article/details/23184501</span></span><br><span class="line">        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>参考：Android避免进入页面EditText自动弹出软键盘 - CSDN博客 <a href="http://blog.csdn.net/Vivian8725118/article/details/23184501" target="_blank" rel="noopener">http://blog.csdn.net/Vivian8725118/article/details/23184501</a>  </p>
<h2 id="2-6-主界面顶部标签文字下的指示器的位置有问题"><a href="#2-6-主界面顶部标签文字下的指示器的位置有问题" class="headerlink" title="2.6. 主界面顶部标签文字下的指示器的位置有问题"></a>2.6. 主界面顶部标签文字下的指示器的位置有问题</h2><p>这是因为代码中用的是绝对位置，不是相对位置引起的。其实这个坑早就该填了，现在使用开源库<strong>CircleIndicator</strong>来重新实现指示器的功能。</p>
<p>CircleIndicator的Github地址：GitHub - ongakuer/CircleIndicator: A lightweight viewpager indicator like in nexus 5 launcher <a href="https://github.com/ongakuer/CircleIndicator" target="_blank" rel="noopener">https://github.com/ongakuer/CircleIndicator</a></p>
<h3 id="2-6-1-首先添加库的依赖（app-build-gradle）："><a href="#2-6-1-首先添加库的依赖（app-build-gradle）：" class="headerlink" title="2.6.1. 首先添加库的依赖（app:build.gradle）："></a>2.6.1. 首先添加库的依赖（app:build.gradle）：</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">dependencies &#123;</span><br><span class="line">    compile <span class="string">'me.relex:circleindicator:1.2.2'</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>添加完后注意点击页面右上角的<code>Sync Now</code>：</p>
<p><img src="http://ozurciydg.bkt.clouddn.com/17-11-23/5028616.jpg" alt="Sync Now"></p>
<h3 id="2-6-2-修改activity-main-xml文件"><a href="#2-6-2-修改activity-main-xml文件" class="headerlink" title="2.6.2. 修改activity_main.xml文件"></a>2.6.2. 修改<code>activity_main.xml</code>文件</h3><p>在<code>activity_main.xml</code>中重新修改标题栏的两个文字属性（宽度改为0，weight改为1:1，margin各距100dp）。<br>然后删除原indicator，新增一个CircleIndicator。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">RelativeLayout</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:app</span>=<span class="string">"http://schemas.android.com/apk/res-auto"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:tools</span>=<span class="string">"http://schemas.android.com/tools"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_width</span>=<span class="string">"match_parent"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">android:layout_height</span>=<span class="string">"match_parent"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">tools:context</span>=<span class="string">"com.likianta.anykey.MainActivity"</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">&lt;!--LinearLayout代替原标题栏的位置--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">LinearLayout</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">"@+id/linearLayout"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">"match_parent"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">"?attr/actionBarSize"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:background</span>=<span class="string">"#ffffff"</span>&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--?attr/actionBarSize表示匹配原actionBar高度--&gt;</span></span><br><span class="line">        </span><br><span class="line">        <span class="comment">&lt;!--显示两个标题--&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:id</span>=<span class="string">"@+id/title_all"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_width</span>=<span class="string">"0dp"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_height</span>=<span class="string">"match_parent"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_marginStart</span>=<span class="string">"100dp"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_weight</span>=<span class="string">"1.0"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:gravity</span>=<span class="string">"center_vertical|end"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:padding</span>=<span class="string">"15dp"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:text</span>=<span class="string">"全部"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:textColor</span>=<span class="string">"@color/mycolorText1"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:textSize</span>=<span class="string">"20sp"</span> /&gt;</span></span><br><span class="line">        </span><br><span class="line">        <span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:id</span>=<span class="string">"@+id/title_new"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_width</span>=<span class="string">"0dp"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_height</span>=<span class="string">"match_parent"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_marginEnd</span>=<span class="string">"100dp"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:layout_weight</span>=<span class="string">"1.0"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:gravity</span>=<span class="string">"center_vertical|start"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:padding</span>=<span class="string">"15dp"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:text</span>=<span class="string">"新增"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:textColor</span>=<span class="string">"@color/mycolorText2"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">android:textSize</span>=<span class="string">"20sp"</span> /&gt;</span></span><br><span class="line">        <span class="comment">&lt;!--这里设置的两个文本的初始状态是文字1是深色，文字2是浅色。</span></span><br><span class="line"><span class="comment">        之后会在函数中实现点击变色的功能--&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="tag">&lt;/<span class="name">LinearLayout</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">&lt;!--制作线条，line1是标题栏下的阴影--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">TextView</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">"@+id/shadow_line1"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">"match_parent"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">"1dp"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_alignBottom</span>=<span class="string">"@id/linearLayout"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:background</span>=<span class="string">"@color/mycolorLineShadow"</span> /&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">&lt;!--制作主体部分viewpager--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">android.support.v4.view.ViewPager</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">"@+id/viewPager"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">"match_parent"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">"wrap_content"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_below</span>=<span class="string">"@id/shadow_line1"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">android.support.v4.view.ViewPager</span>&gt;</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment">&lt;!--指示器，紧贴着文字下方的一个小短线，用于指示当前页面编号--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">me.relex.circleindicator.CircleIndicator</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:id</span>=<span class="string">"@+id/indicator"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_width</span>=<span class="string">"match_parent"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_height</span>=<span class="string">"5dp"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_above</span>=<span class="string">"@id/viewPager"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">android:layout_marginBottom</span>=<span class="string">"1dp"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:ci_drawable</span>=<span class="string">"@drawable/shape_indicator"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:ci_margin</span>=<span class="string">"22dp"</span></span></span><br><span class="line"><span class="tag">        <span class="attr">app:ci_width</span>=<span class="string">"25dp"</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">RelativeLayout</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>在CircleIndicator中用到了<code>app:ci_drawable=&quot;@drawable/shape_indicator&quot;</code>，这个shape只是一个简单的黑色背景，代码如下（在drawable目录下新建<code>shape_indicator.xml</code>）：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">shape</span> <span class="attr">xmlns:android</span>=<span class="string">"http://schemas.android.com/apk/res/android"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">solid</span> <span class="attr">android:color</span>=<span class="string">"@color/mycolorText1"</span> /&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">corners</span> <span class="attr">android:radius</span>=<span class="string">"8dp"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">shape</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>实际效果图如下：</p>
<p><img src="http://ozurciydg.bkt.clouddn.com/17-12-1/89019773.jpg" alt=""></p>
<h3 id="2-6-3-在MainActivity中创建indicator并绑定"><a href="#2-6-3-在MainActivity中创建indicator并绑定" class="headerlink" title="2.6.3. 在MainActivity中创建indicator并绑定"></a>2.6.3. 在MainActivity中创建indicator并绑定</h3><p><code>MainActivity.java</code></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MainActivity</span> <span class="keyword">extends</span> <span class="title">AppCompatActivity</span> <span class="keyword">implements</span> <span class="title">View</span>.<span class="title">OnClickListener</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> CircleIndicator indicator; <span class="comment">//将原先的ImageView indicator改为CircleIndicator indicator滚动指示器</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/*这三行可以删掉了</span></span><br><span class="line"><span class="comment">    private int offset = 0; //滚动条初始偏移量</span></span><br><span class="line"><span class="comment">    private int currIndex = 0; //当前页编号</span></span><br><span class="line"><span class="comment">    private int bmpW; //滚动条宽度</span></span><br><span class="line"><span class="comment">    private int one; //一倍滚动量</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onCreate</span><span class="params">(Bundle savedInstanceState)</span> </span>&#123;</span><br><span class="line">        </span><br><span class="line">        indicator = (CircleIndicator) findViewById(R.id.indicator);</span><br><span class="line"></span><br><span class="line">        ...</span><br><span class="line"></span><br><span class="line">        <span class="comment">//初始化适配器数据</span></span><br><span class="line">        PagerAdapter pagerAdapter = <span class="keyword">new</span> PagerAdapter() &#123;...&#125;;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//绑定适配器</span></span><br><span class="line">        viewPager.setAdapter(pagerAdapter);</span><br><span class="line">        <span class="comment">//装载indicator，只需短短一行代码就替代了之前的初始化、一倍位移量等各种操作</span></span><br><span class="line">        indicator.setViewPager(viewPager);</span><br><span class="line"></span><br><span class="line">        <span class="comment">//设置viewPager的初始界面为第一个界面</span></span><br><span class="line">        ...</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//页面滚动监听器功能，实现标签页左右滑动切换效果</span></span><br><span class="line">    <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyOnPageChangeListener</span> <span class="keyword">implements</span> <span class="title">ViewPager</span>.<span class="title">OnPageChangeListener</span> </span>&#123;</span><br><span class="line">        </span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onPageSelected</span><span class="params">(<span class="keyword">int</span> index)</span> </span>&#123;</span><br><span class="line">            <span class="keyword">switch</span> (index) &#123;</span><br><span class="line">                <span class="keyword">case</span> <span class="number">0</span>:</span><br><span class="line">                    titleAll.setTextColor(<span class="number">0xff000000</span>);<span class="comment">//0x表示整型，ff表示透明度为0，最后的6位数字表示颜色，必须这样写，不能省略</span></span><br><span class="line">                    titleNew.setTextColor(<span class="number">0xff8e8e8e</span>);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">                <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">                    titleNew.setTextColor(<span class="number">0xff000000</span>);</span><br><span class="line">                    titleAll.setTextColor(<span class="number">0xff8e8e8e</span>);</span><br><span class="line">                    <span class="keyword">break</span>;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onPageScrolled</span><span class="params">(<span class="keyword">int</span> arg0, <span class="keyword">float</span> arg1, <span class="keyword">int</span> arg2)</span> </span>&#123;</span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">        <span class="meta">@Override</span></span><br><span class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onPageScrollStateChanged</span><span class="params">(<span class="keyword">int</span> arg0)</span> </span>&#123;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/*这里可以删除了</span></span><br><span class="line"><span class="comment">    public void InitScrollbar(int bmpW) &#123;...&#125;</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<hr>
<h1 id="3-布局地图"><a href="#3-布局地图" class="headerlink" title="3. 布局地图"></a>3. 布局地图</h1><p>该流程图用于梳理整体的布局逻辑以及命名规范：</p>
<p><img src="http://ozurciydg.bkt.clouddn.com/17-11-30/37284633.jpg" alt=""></p>
<hr>
<h1 id="相关参考"><a href="#相关参考" class="headerlink" title="相关参考"></a>相关参考</h1><ol>
<li>Android 手动显示和隐藏软键盘 - 一点点征服 - 博客园 <a href="https://www.cnblogs.com/ldq2016/p/6861128.html" target="_blank" rel="noopener">https://www.cnblogs.com/ldq2016/p/6861128.html</a>  </li>
<li><a href="http://m.blog.csdn.net/wenxin2011/article/details/50845563" target="_blank" rel="noopener">http://m.blog.csdn.net/wenxin2011/article/details/50845563</a></li>
<li>安卓开发-Activity中finish() onDestroy() 和System.exit()的区别 - CSDN博客 <a href="http://blog.csdn.net/imzoer/article/details/9380807" target="_blank" rel="noopener">http://blog.csdn.net/imzoer/article/details/9380807</a>  </li>
<li>Android避免进入页面EditText自动弹出软键盘 - CSDN博客 <a href="http://blog.csdn.net/Vivian8725118/article/details/23184501" target="_blank" rel="noopener">http://blog.csdn.net/Vivian8725118/article/details/23184501</a>  </li>
<li>第三方框架ViewPagerIndicator引入到Android Studio的方法总结 - chironmy - 博客园 <a href="https://www.cnblogs.com/baipengzhan/p/6286619.html" target="_blank" rel="noopener">https://www.cnblogs.com/baipengzhan/p/6286619.html</a></li>
<li>GitHub - ongakuer/CircleIndicator: A lightweight viewpager indicator like in nexus 5 launcher <a href="https://github.com/ongakuer/CircleIndicator" target="_blank" rel="noopener">https://github.com/ongakuer/CircleIndicator</a></li>
<li>android开发之GridLayout详解 - CSDN博客 <a href="http://blog.csdn.net/huangxiaominglipeng/article/details/17448045" target="_blank" rel="noopener">http://blog.csdn.net/huangxiaominglipeng/article/details/17448045</a></li>
<li>scrollview底部加入不滑动的button - CSDN博客 <a href="http://blog.csdn.net/lzq520210/article/details/49333321" target="_blank" rel="noopener">http://blog.csdn.net/lzq520210/article/details/49333321</a></li>
<li><strong>【Android】EditText 遇到软键盘遮挡底部一点的问题 - CSDN博客 <a href="http://blog.csdn.net/xiaoguda1/article/details/52084248" target="_blank" rel="noopener">http://blog.csdn.net/xiaoguda1/article/details/52084248</a> </strong></li>
<li>android selector 和 layer-list复合使用 - CSDN博客 <a href="http://blog.csdn.net/qq_20976303/article/details/51162649" target="_blank" rel="noopener">http://blog.csdn.net/qq_20976303/article/details/51162649</a></li>
<li>Android 显示和隐藏软键盘 - 简书 <a href="http://www.jianshu.com/p/dc9387417914" target="_blank" rel="noopener">http://www.jianshu.com/p/dc9387417914</a></li>
</ol>
<hr>
<h1 id="日志"><a href="#日志" class="headerlink" title="日志"></a>日志</h1><p><strong>2017年11月26日</strong>  </p>
<ol>
<li>【修改】解决登录界面密码输入错误键盘无法自动回弹的问题  </li>
<li>【更新】登录界面的欢迎语的判断逻辑统一放在changeLoginWelcome()中  </li>
<li>【更新】当登录密码输入错误时，欢迎语变为红色并闪烁一下（利用AlphaAnimation属性）  </li>
</ol>
<p><strong>2017年11月27日</strong>  </p>
<ol>
<li>【修改】解决登录界面按返回键无法退出的问题</li>
<li>【修改】解决一进入主界面键盘就自动弹出的问题</li>
<li>【更新】解决指示器位置不准确的问题，换用开源库CircleIndicator实现指示器功能</li>
<li><strong>【修改】解决EditText的背景的下半边被软键盘遮挡的问题</strong></li>
<li>【新增】制作布局地图，梳理逻辑</li>
</ol>
<p><strong>2017年11月28日</strong></p>
<ol>
<li><strong>【创建】<a href="https://github.com/Likianta/anykey" target="_blank" rel="noopener">Github Project</a></strong></li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
        <div class="post-widgets">
        

        

        
          
          <div id="needsharebutton-postbottom">
            <span class="btn">
              <i class="fa fa-share-alt" aria-hidden="true"></i>
            </span>
          </div>
        
        </div>
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/1128200920/" rel="next" title="使用Git Bash将本地项目push到远程版本库">
                <i class="fa fa-chevron-left"></i> 使用Git Bash将本地项目push到远程版本库
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/1201210059/" rel="prev" title="adb shell cd进包名路径提示没有访问权限的解决办法">
                adb shell cd进包名路径提示没有访问权限的解决办法 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNDI4MS8xMDgxOA=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="http://ozurciydg.bkt.clouddn.com/18-2-12/72826549.jpg"
                alt="Likianta" />
            
              <p class="site-author-name" itemprop="name">Likianta</p>
              <p class="site-description motion-element" itemprop="description">Android Dev</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">73</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="http://blog.csdn.net/likianta" target="_blank" title="CSDN">
                      
                        <i class="fa fa-fw fa-crosshairs"></i>CSDN</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:sheerish@qq.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/likianta" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/5441767757/profile?rightmod=1&wvr=6&mod=personinfo" target="_blank" title="Weibo">
                      
                        <i class="fa fa-fw fa-weibo"></i>Weibo</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-先讲一下如何在真机上调试app"><span class="nav-text">1. 先讲一下如何在真机上调试app</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-实机测试问题汇总"><span class="nav-text">2. 实机测试问题汇总</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#2-1-首次创建密码后无法进入主界面"><span class="nav-text">2.1. 首次创建密码后无法进入主界面</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-2-登录界面在输入错误时软键盘不能自动弹出"><span class="nav-text">2.2. 登录界面在输入错误时软键盘不能自动弹出</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-3-密码错误时的提示语不醒目"><span class="nav-text">2.3. 密码错误时的提示语不醒目</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-4-在登录界面按返回键无法退出"><span class="nav-text">2.4. 在登录界面按返回键无法退出</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-5-一进入主界面软键盘就自动弹出"><span class="nav-text">2.5. 一进入主界面软键盘就自动弹出</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-6-主界面顶部标签文字下的指示器的位置有问题"><span class="nav-text">2.6. 主界面顶部标签文字下的指示器的位置有问题</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-6-1-首先添加库的依赖（app-build-gradle）："><span class="nav-text">2.6.1. 首先添加库的依赖（app:build.gradle）：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-6-2-修改activity-main-xml文件"><span class="nav-text">2.6.2. 修改activity_main.xml文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-6-3-在MainActivity中创建indicator并绑定"><span class="nav-text">2.6.3. 在MainActivity中创建indicator并绑定</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-布局地图"><span class="nav-text">3. 布局地图</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#相关参考"><span class="nav-text">相关参考</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#日志"><span class="nav-text">日志</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; 2017 &mdash; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Likianta</span>

  
</div>


  <div class="powered-by">
    <i class="fa fa-user-md"></i>
    <span id="busuanzi_container_site_pv">
      Site visitors:<span id="busuanzi_value_site_pv"></span>
    </span>
  </div>

<!--
  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.3</div>

-->



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">Site words total count:75.2k</span>
</div>
        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  





  

  

  

  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
      pbOptions = {};
      
          pbOptions.iconStyle = "box";
      
          pbOptions.boxForm = "horizontal";
      
          pbOptions.position = "bottomCenter";
      
          pbOptions.networks = "Weibo,Wechat,Douban,QQZone,Evernote";
      
      new needShareButton('#needsharebutton-postbottom', pbOptions);
    
    
  </script>

  

  

  

  

</body>
</html>
